package com.gec;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.google.gson.Gson;

public class AliyunSmsDemo {

    public static void main(String[] args) throws ClientException {
        // 设置AccessKey ID和AccessKey Secret
        String accessKeyId = "your_access_key_id";
        String accessKeySecret = "your_access_key_secret";

        // 设置短信签名和模板CODE
        String signName = "your_sign_name";
        String templateCode = "your_template_code";

        // 设置接收短信的手机号码
        String phoneNumbers = "13686778922";

        // 创建默认的AcsClient实例
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
        DefaultProfile.addEndpoint("cn-hangzhou", "Dysmsapi", "dysmsapi.aliyuncs.com");
        IAcsClient client = new DefaultAcsClient(profile);

        // 创建SendSmsRequest对象，并设置相关参数
        SendSmsRequest request = new SendSmsRequest();
        request.setPhoneNumbers(phoneNumbers);
        request.setSignName(signName);
        request.setTemplateCode(templateCode);

        // 发送短信验证码
        SendSmsResponse sendSmsResponse = client.getAcsResponse(request);
        Gson gson = new Gson();
        String jsonString = gson.toJson(sendSmsResponse);
        System.out.println("发送短信验证码结果：" + jsonString);
    }
}
